package com.mk;

import com.mk.mapper.UserMapperTest;
import lombok.SneakyThrows;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * @ClassName mybatis
 * @Description TODO
 * @Author makai
 * @Date 2023/10/20 22:32
 */
public class MybatisTest3
{

    @SneakyThrows
    @Test
    public void test()
    {
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis-config-test.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        UserMapperTest mapper = sqlSession.getMapper(UserMapperTest.class);
        mapper.getUsers2();
        //提交事务、二级缓存
        sqlSession.commit();

        SqlSession sqlSession2 = sqlSessionFactory.openSession();
        UserMapperTest mapper2 = sqlSession2.getMapper(UserMapperTest.class);
        mapper2.getUsers2();
    }

}
